<%@ Language=VBScript %>
<%Option Explicit%>

<!--#include file="../cons.asp"-->
<!--#include file="../../Common/Database.asp"-->

<%
	response.CacheControl = "no-cache"

	Dim oRSAlumnos
	Dim IdAlumno
	
	IdAlumno = Request("IdAlumno")
	
	Set oRSAlumnos = GetPromMateria(request("IdAlumno"))
	
	%>
	<table cellpadding=0 cellspacing=0 width=100% height=100% style="border-collapse: collapse; font-family: Verndana; font-size: 12px; font-weight: bold; color: white;">
		<tr valign="top">
			<td style="background-color: #666666; width: 270px; height: 15px;">Apellido y Nombre</td>
			<td style="background-color: #666666; text-align: center;">Prom.</td>
			<td style="background-color: #666666; text-align: center;">Ev.</td>
			<td style="background-color: #666666; text-align: center; width:20;"></td>
		</tr>
		<tr valign="top">
			<td colspan=5>
				<div style="height: 300px; overflow-Y: scroll;">
		<table cellpadding=0 cellspacing=0 width=100% height=100% style="border-collapse: collapse; font-family: Verndana; font-size: 12px;">
		<%
			while not oRSAlumnos.EOF
				response.Write "<tr>"
				response.Write "<td width=270 height=25>" & server.HTMLEncode(oRSAlumnos("MateriaBoletin")) & "</td>"
				response.Write "<td style=""text-align: center;"">" & GetNotaDecCol(oRSAlumnos("promnota"), 2) & "</td>"
				response.Write "<td style=""text-align: center;""><img src=""../../images/ico_grillaEv.gif"" title=""Grafico Evolucion Alumno"" style=""cursor: hand;"" onclick=""PopupEvAlumno("& IdAlumno & ", " & oRSAlumnos("IdSede") & ",'" & oRSAlumnos("IdMateria") & "');""></img></td>"
				response.Write "<td></td>"
				response.Write "</tr>"
				
				oRSAlumnos.MoveNext()
			wend
		%>
		</table>
		</div>
		</td>
		</tr>
		
	</table>
	
	<%


Private function GetPromMateria(IdAlumno)

	Dim oConn, sSQL, oRS

	Set oConn = OpenConnection

'	sSQL =	"select M.IdMateria, M.MateriaBoletin, MC.IdSedeCurso, avg(Nota) as promnota from Nota N " & _
'			"inner join AlumnoCurso AC on (AC.IdAlumnoCurso = N.IdAlumnoCurso and IdAlumno = " & IdAlumno &") " & _
'			"inner join MateriaCurso MC on (MC.IdMateriaCurso = AC.IdMateriaCurso) " & _
'			"inner join ProfesorMateria PM on (PM.IdProfesorMateria = MC.IdProfesorMateria) " & _
'			"inner join Materia M on (PM.IdMateria = M.IdMateria) " & _
'			"group by N.IdAlumnoCurso " & _
'			"order by promnota desc"

    sSQL =  "select M.IdMateria, M.MateriaBoletin, C.IdSede, avg(NM.Nota) as promnota " & _
            "from NotasModalidad NM " & _
            "inner join AlumnosCurso AC on (AC.IdAlumno = " & IdAlumno & ") " & _
            "inner join Notas N on (N.IdNota = NM.IdNota and N.IdAlumnoCurso = AC.IdAlumnoCurso) " & _
            "inner join Curso C on (C.IdCurso = AC.IdCurso) " & _
            "inner join Materia M on (M.IdMateria = N.IdMateria) " & _
            "group by M.IdMateria, M.MateriaBoletin, C.IdSede " & _
            "order by MateriaBoletin"

	'response.Write sSQL
	'response.End	
	Set oRS = oConn.Execute(sSQL)
	
	Set GetPromMateria = oRS
End function

Public function GetNotaDecCol(nota, idec)
	Dim sNota, iNotaConvert
	
	iNotaConvert = FormatNumber(nota, idec)
	
	sNota = "<font color="""
	if iNotaConvert >= 0 and iNotaConvert < 4 then
		sNota = sNota & "red"
	end if
	
	if iNotaConvert >= 4 and iNotaConvert < 6 then
		sNota = sNota & "green"
	end if
	
	if iNotaConvert >= 6 and iNotaConvert <= 10 then
		sNota = sNota & "blue"
	end if
	
	sNota = sNota & """>" & iNotaConvert & "</font>"
	GetNotaDecCol = sNota
End function
%>